<template>
  <div class="bind-content">
    <van-cell-group>
      <van-field v-model="value" placeholder="请输入支付宝账号"/>
    </van-cell-group>
    <van-cell-group>
      <van-field v-model="value2" placeholder="请输入支付宝姓名"/>
    </van-cell-group>
    <div class="bindbtn" @click="Suk_bind">绑定</div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      value: "",
      value2: ""
    };
  },
  beforeCreate: function() {
    //创建前
  },
  created: function() {
    var that=this;
    //创建后
    var obj = {
      id: localStorage.getItem("userid")
    };
    that.axios
      .post(that.baseUrl + "/user/queryUser", that.Qs.stringify(obj), {
        headers: {
          "Content-Type": "application/x-www-form-urlencoded"
        }
      })
      .then(function(res) {
        if (res.request.status === 200) {
          console.log(res.data, "user");
          if (res.data.meta.code == 200) {
            that.value = res.data.data.payZhifu
            that.value2 = res.data.data.payZhifu2
          } else {
            console.log("fail");
          }
        }
      });
  },
  beforeMount: function() {
    //挂载前
  },
  mounted: function() {
    //挂载后
  },
  beforeUpdate: function() {
    //更新前
  },
  update: function() {
    //更新后
  },
  methods: {
    Suk_bind() {
      let that = this;
      if(that.value == ""){
        that.$toast.fail({
          message:'手机不能为空'
        });
        return
      }
      if(that.value2 == ""){
        that.$toast.fail({
          message:'姓名不能为空'
        });
        return
      }
      that.$toast.loading({
        message: "加载中..."
      });
      var Sukdata = {
          payZhifu:that.value,
          payZhifu2:that.value2,
          userId:localStorage.getItem('userid')
      };
      console.log(Sukdata);
      that.axios
        .post(that.baseUrl + "/user/addBangDingZhiFuBao", that.Qs.stringify(Sukdata), {
          headers: {
            "Content-Type": "application/x-www-form-urlencoded"
          }
        })
        .then(function(res) {
          if (res.request.status === 200) {
            if (res.data.meta.code == 200) {
              console.log(res.data);
              that.$toast.success({
                  message:'绑定成功'
              });
              setTimeout(function(){ that.$router.go(-1); },2000);

            } else if (res.data.meta.code == 501) {
            }else{
              that.$toast.success({
                message:'绑定失败请检查姓名与支付宝账号是否匹配！'
              });
            }
          }
        });
    }
  }
};
</script>
<style lang="scss" scoped>
.bind-content {
}
.bindbtn {
  width: 90%;
  background: #fda229;
  height: 1rem;
  line-height: 1rem;
  text-align: center;
  color: #fff;
  margin: 0 auto;
  border-radius: 0.5rem;
  margin-top: 2rem;
  font-size: 0.4rem;
}
</style>
